home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 376-400 / disk_400 / setcpu / setcpu.h < prev    next >
C/C++ Source or Header  |  1992-05-06  |  10KB  |  370 lines

  1. /*
  2.     SetCPU V1.60
  3.     by Dave Haynie, April 13, 1990
  4.     Released to the Public Domain
  5.  
  6.     HEADER FILE
  7. */
  8.  
  9.  
  10. #define PROGRAM_VERSION    160
  11.  
  12. #include <exec/types.h>
  13. #include <exec/execbase.h>
  14. #include <exec/nodes.h>
  15. #include <exec/lists.h>
  16. #include <exec/memory.h>
  17. #include <exec/io.h>
  18. #include <devices/trackdisk.h>
  19. #include <libraries/expansionbase.h>
  20. #include <libraries/configregs.h>
  21. #include <libraries/configvars.h>
  22. #include <graphics/gfxbase.h>
  23. #include <graphics/gfxmacros.h>
  24. #include <intuition/intuition.h>
  25. #include <intuition/intuitionbase.h>
  26. #include <libraries/dosextens.h>
  27. #include <libraries/filehandler.h>
  28. #include <functions.h>
  29. #include <stdio.h>
  30. #include <ctype.h>
  31.  
  32. /* ====================================================================== */
  33.  
  34. /* Define all bit components used for manipulation of the Cache Control
  35.    Register. */
  36.  
  37. #define CACR_INST    ((ULONG)(1L<<0))
  38. #define CACR_DATA    ((ULONG)(1L<<8))
  39. #define CACR_FIXED    ((ULONG)(CACR_DATA<<CACR_WALLOC))
  40.  
  41. #define CACR_WALLOC    5
  42. #define CACR_BURST    4
  43. #define CACR_CLEAR    3
  44. #define CACR_ENTRY    2
  45. #define CACR_FREEZE    1
  46. #define CACR_ENABLE    0
  47.  
  48. #define CACR_ENABLE40    15
  49. #define CACR_DATA40    16
  50.  
  51. /* ====================================================================== */
  52.  
  53. /* Define important bits used in various MMU registers. */
  54.  
  55. /* Here are the CRP definitions.  The CRP register is 64 bits long, but
  56.    only the first 32 bits are control bits, the next 32 bits provide the
  57.    base address of the table. */
  58.  
  59. #define    CRP_UPPER    (1L<<31)        /* Upper/lower limit mode */
  60. #define CRP_LIMIT(x)    ((ULONG)((x)&0x7fff)<<16)/* Upper/lower limit value */
  61. #define CRP_SG        (1L<<9)            /* Indicates shared space */
  62. #define CRP_DT_INVALID    0x00            /* Invalid root descriptor */
  63. #define    CRP_DT_PAGE    0x01            /* Fixed offset, auto-genned */
  64. #define CRP_DT_V4BYTE    0x02            /* Short root descriptor */
  65. #define    CRP_DT_V8BYTE    0x03            /* Long root descriptor */
  66.  
  67. /* Here are the TC definitions.  The TC register is 32 bits long. */
  68.  
  69. #define    TC_ENB        (1L<<31)        /* Enable the MMU */
  70. #define    TC_SRE        (1L<<25)        /* For separate Supervisor */
  71. #define    TC_FCL        (1L<<24)        /* Use function codes? */
  72. #define    TC_PS(x)    ((ULONG)((x)&0x0f)<<20)    /* Page size */
  73. #define TC_IS(x)    ((ULONG)((x)&0x0f)<<16)    /* Logical shift */
  74. #define    TC_TIA(x)    ((ULONG)((x)&0x0f)<<12)    /* Table indices */
  75. #define    TC_TIB(x)    ((ULONG)((x)&0x0f)<<8)
  76. #define TC_TIC(x)    ((ULONG)((x)&0x0f)<<4)
  77. #define    TC_TID(x)    ((ULONG)((x)&0x0f)<<0)
  78.  
  79. /* Here are the page descriptor definitions, for short desctriptors only,
  80.    since that's all I'm using at this point. */
  81.    
  82. #define    PD_ADDR(x)    ((ULONG)(x)&~0x0fL)    /* Translated Address */
  83. #define IV_ADDR(x)    ((ULONG)(x)&~0x03L)    /* Invalid unused field */    
  84. #define    PD_WP        (1L<<2)            /* Write protect it! */
  85. #define PD_CI        (1L<<6)            /* Cache inhibit */
  86. #define PD_DT_TYPE    0x03            /* Page descriptor type */
  87. #define PD_DT_INVALID    0x00            /* Invalid root descriptor */
  88. #define    PD_DT_PAGE    0x01            /* Fixed offset, auto-genned */
  89. #define PD_DT_V4BYTE    0x02            /* Short root descriptor */
  90. #define    PD_DT_V8BYTE    0x03            /* Long root descriptor */
  91.  
  92. /* This is needed for identification of bogus systems that test positive
  93.    for MMUs. */
  94.  
  95. #define BOGUSMMU    0xffffffffL
  96.  
  97. /* Here's the MMU support stuff. */
  98.  
  99. #define ROMROUND    0x00020000L    /* ROM/Main level at 128K grain */
  100. #define SMALLROMSIZE    0x00040000L
  101. #define BIGROMSIZE    0x00080000L
  102. #define DEVROUND    0x00004000L    /* Device level at 16K grain */
  103. #define STKROUND    0x00000400L    /* Stack level at 1K grain */
  104. #define TABROUND    0x00000400L    /* Table alignment matches page size */
  105. #define PAGESIZE    0x00020000L
  106. #define MAINTABSIZE    (128L * sizeof(ULONG))
  107. #define SUBTABSIZE    (8L * sizeof(ULONG))
  108. #define STKTABSIZE    (16L * sizeof(ULONG))
  109.  
  110. /* Magic ROM numbers */
  111.  
  112. #define MAGIC_256    0x11114ef9
  113. #define MAGIC_512    0x11144ef9
  114.    
  115. /* ====================================================================== */
  116.  
  117. /* Some external system declarations. */
  118.  
  119. extern BPTR Lock(), Open();
  120.  
  121. /* Checking logic */
  122.  
  123. #define    CK68000        0
  124. #define CK68010        1
  125. #define CK68020        2
  126. #define CK68030        3
  127. #define CK68040        4
  128. #define CK68851        5
  129. #define CK68881        6
  130. #define CK68882        7
  131. #define CKFPU        8
  132. #define CKMMU        9
  133. #define CKMMUON        10
  134. #define CKMMUROM    11
  135. #define CKMMUALIEN    12
  136. #define CHECKS        13
  137.  
  138. #define    WARNING    5
  139. #define READOK    0L
  140.  
  141. #define SizeOf(x)    ((ULONG)sizeof(x))
  142. #define min(a,b)    ((a<b)?a:b)
  143. #define max(a,b)    ((a>b)?a:b)
  144.  
  145. /* ====================================================================== */
  146.  
  147. /* From the CONTROL.A module */
  148.  
  149. extern void            SetCACR(),
  150.                  GetCRP(),
  151.                 SetCRP(),
  152.                 SetTC();
  153.  
  154. extern ULONG            GetCACR(),
  155.                 *GetVBR(),
  156.                  GetTC();
  157.  
  158. /* ====================================================================== */
  159.  
  160. /* From the IDENTS.A module */
  161.  
  162. extern ULONG            GetCPUType(),
  163.                 GetMMUType(),
  164.                 GetFPUType();
  165.  
  166. /* ====================================================================== */
  167.  
  168. /* From the OTHER.A module */
  169.  
  170. extern void            SetMMUTag(),
  171.                 FlushATC(),
  172.                 SetKeyDelay();
  173.  
  174. extern ULONG            KeyCode,
  175.                 KeyCodeSize,
  176.                 BerrCode,
  177.                 BerrCodeSize;
  178.  
  179. /* ====================================================================== */
  180.  
  181. /* From the REBOOT.A module. */
  182.  
  183. extern void             ROMBoot(),
  184.                 CleanBoot();
  185.  
  186. extern ULONG            BootCode,
  187.                 BootCodeSize,
  188.                 ResetCode,
  189.                 ResetCodeSize;
  190.  
  191.  
  192. /* ====================================================================== */
  193.  
  194. /* From the EXPDEV.C module. */
  195.  
  196. /* This structure is device information used by the memory mapping routine. */
  197.  
  198. struct ExpROMData {
  199.    struct ExpROMData *next;
  200.    ULONG ROMbase;
  201.    ULONG ROMsize;
  202.    ULONG imagebase;
  203.    ULONG tablebase;
  204.    char *name;    
  205. };
  206.  
  207. extern LONG                ReadExpDevs();
  208. extern struct ExpROMData        *GetExpROM();
  209. extern void                FreeExpROM(),
  210.                     SafeConfigDevs();
  211.  
  212. /* ====================================================================== */
  213.  
  214. /* From the MISC.C module. */
  215.  
  216. /* Patch types */
  217.  
  218. #define PT_STRING    1
  219. #define PT_JSR        2
  220. #define PT_END        3
  221. #define PT_IGNORE    4
  222. #define PT_KEYBOARD    5
  223.  
  224. /* This is a item */
  225.  
  226. struct pitem {
  227.    UWORD Type;        /* The type of patch to apply */
  228.    UWORD Pad;        /* Nothing here yet... */
  229.    ULONG Offset;    /* The offset at which to apply the patch */
  230.    ULONG Length;    /* The length of the patch item */
  231.    UWORD *Code;        /* The actual patch item */
  232. };
  233.  
  234. /* This is the patch structure. */
  235.  
  236. struct patch {
  237.    struct patch *next;    /* Next patchlist */
  238.    struct pitem *list;    /* First item in this patchlist */
  239.    UWORD Version;    /* Which ROM version */
  240.    UWORD Revision;    /*   and revision */
  241. };
  242.  
  243. /* These are the some patch system variables. */
  244.  
  245. #define KEYPATCH        0
  246.  
  247. extern struct patch         SystemPatch[];
  248. extern struct MemChunk         *lastpatch;
  249.  
  250. /* The actual functions. */
  251.  
  252. extern LONG            striequ(),
  253.                 strniequ();
  254.  
  255. extern void            MotorOff();
  256. extern BYTE            ReadBuf();
  257. extern LONG            CheckTDDev();
  258.  
  259. extern LONG            AddPatch();
  260.  
  261. /* ====================================================================== */
  262.  
  263. /* From the MMU.C module. */
  264.  
  265. extern void             Phantom(),
  266.                 SetMMURegs(),
  267.                 FillBasicTable(),
  268.                 FreeMMUTable(),
  269.                 MakeExpTable(),
  270.                 MakeFastStack(),
  271.                 FreeFastStack();
  272.  
  273. /* ====================================================================== */
  274.  
  275. /* From the MEMORY.C module. */
  276.  
  277. /* This section describes the system tag structure, where I stick all the
  278.    information that I like to keep around.  */
  279.    
  280. #define ROM_NOP            0x0000    /* No ROM operation called for */
  281. #define ROM_FAST        0x0002    /* Normally installed FASTROM image */
  282. #define ROM_KICK        0x0003    /* Installed as a KICK image */
  283. #define ROM_FKICK        0x0004    /* A KICK image made into a FAST image */
  284.  
  285. /* This was originally the patchtag structure, which looked like a patch.  I 
  286.    decided that was real kludgy.  I hook the systag onto an invalid page 
  287.    descriptor which I locate in the physical ROM image, a place that should 
  288.    always be safe to have an invalid tag structure.  Don't change this without
  289.    checking in the "030Stuff.a" file -- some of these structure members are
  290.    used by the reboot code. */
  291.  
  292. struct systag {
  293.    ULONG         tagsize;    /* Size of this tag */
  294.    ULONG         progver;    /* The program version */
  295.    ULONG        *maintable;    /* The main ROM table */
  296.    ULONG        *romhi;        /* The main ROM image */
  297.    UWORD         romtype;    /* Type of MMU ROM */
  298.    UWORD         patches;    /* The number of other patches applied */
  299.    struct MemChunk     *patchlist;    /* List of installed patches */
  300.    struct ExpROMData    *devs;        /* Translated device ROMs */
  301.    ULONG        TC;        /* Precomputed TC used for KICK. */
  302.    ULONG        CRP[2];        /* Precomputed CRP used for KICK. */
  303.    UWORD        config;        /* Configuration status. */
  304.    ULONG        BerrSize;    /* Size of bus error handler. */
  305.    char            *OldBerr;    /* The old BERR routine. */
  306.    char            *BerrHandler;    /* My BERR routine. */
  307.    short        wrapup;        /* Upper address wrap bound. */
  308.    short        wrapdown;    /* Lower address wrap bound. */
  309.    ULONG        tablesize;    /* Main table size. */
  310.    char            *ResetCode;    /* Actual reset routine */
  311.    ULONG        romsize;    /* Size of ROM image */
  312.    ULONG        romloc;        /* Where does the fool thing go? */
  313.    ULONG        romstart;    /* And where do we start it up? */
  314.    ULONG        *romlo;        /* Secondary ROM image, if needed */
  315.    char            *sysstack;    /* Physical system stack image */
  316.    ULONG        sysstksize;    /* System Stack allocated size. */
  317.    ULONG        ResetSize;    /* Size of the reset code. */
  318.    char            *OldReset;    /* Old Reset Code */
  319. };
  320.  
  321. /* The actual functions */
  322.  
  323. extern void             MemCopy(),
  324.                 SetMMURegs(),
  325.                 *AllocAligned(),
  326.                 SnoopSpecial(),
  327.                 FillBasicTable(),
  328.                 FreeSAFEImage();
  329. ULONG *                SizeROM();
  330. extern struct systag        *AllocROMImage(),
  331.                 *AllocDISKImage(),
  332.                 *AllocSAFEImage(),
  333.                 *GetSysTag();
  334. extern LONG            SmartlyGetRange();
  335.  
  336. /* ====================================================================== */
  337.  
  338. /* From the DISKIO.C module. */
  339.  
  340. extern struct systag     *AllocKSImage(),
  341.             *AllocFILEImage(),
  342.             *AllocDISKImage();
  343.  
  344. /* ====================================================================== */
  345.  
  346. /* From the COOLHAND.C module. */
  347.  
  348. struct Window *CoolHand();
  349.  
  350. /* ====================================================================== */
  351.  
  352. /* Intermodule globals */
  353.  
  354. struct CfgBlock {
  355.    ULONG Addr, Size;
  356. };
  357.  
  358. #ifdef MAIN_MODULE
  359. struct ExpansionBase *ExpansionBase = NULL;    /* The expansion library */
  360. unsigned short LoadErr = 16;
  361. struct CfgBlock Bridge = { 0L, 0L }, A26x0 = { 0L, 0L };
  362. #else
  363. extern struct ExpansionBase *ExpansionBase;
  364. extern unsigned short LoadErr, forcewrap;
  365. extern struct CfgBlock Bridge, A26x0;
  366. extern BOOL allochead,aliens;
  367. extern ULONG cpu;
  368. #endif
  369.  
  370.